package jdbc;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

/**
 * 使用预编译sql完成更新操作
 * 根据id
 */
public class Demo10 {
    public static void main(String[] args){
        try(Connection conn = DBUtil.getConnection()) {
            String sql = "UPDATE user SET name=?,password=?,nickname=?,age=?";
            PreparedStatement ps = conn.prepareStatement(sql);
            ps.setString(1,"lisi");
            ps.setString(2,"123456");
            ps.setString(3,"李四");
            ps.setInt(4,20);
            int num = ps.executeUpdate();
            System.out.println(num>0?"更新成功":"更新失败");
        }catch (SQLException e){
            e.printStackTrace();
        }
    }
}
